package cn.edu.sju;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * 
 练习2
 */
public class Exercise02
{
    
    public static void main(String[] args) throws IOException
    {
     // 1. 创建文件输入流对象
        FileInputStream fis = new FileInputStream("E:\\example03.txt");
        // 2. 读取字节数据
        int n1 = fis.read();
        int n2 = fis.read();
        
        System.out.println(n1);
        System.out.println(n2);
        
        byte[] buf = new byte[8];
        
        fis.read(buf);
        
        System.out.println(new String(buf, StandardCharsets.UTF_8));
        
        buf = new byte[100];
        int s = fis.read(buf);
        System.out.println(new String(buf, 0, s, StandardCharsets.UTF_8));
        System.out.println("最后一行是" + s + "个字节");
        // 3. 关闭输入流对象
        fis.close();
        
    }
    
}
